package com.movitech.mobile.cz.base.purchase.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.google.common.collect.Maps;
import com.movitech.mobile.cz.base.common.license.LicenseUtil;
import com.movitech.mobile.cz.base.purchase.bizvo.outer.BidManageReqVo;
import com.movitech.mobile.cz.base.purchase.entity.WFlowFormExtMng;
import com.movitech.mobile.cz.base.purchase.entity.ext.ExtWFlowFormExtMng;
import com.movitech.mobile.cz.base.purchase.mapper.WFlowFormExtMngMapper;
import com.movitech.mobile.cz.base.purchase.mapper.ext.ExtWFlowFormExtMngMapper;
import com.movitech.mobile.cz.base.purchase.service.WFlowFormExtMngService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 * 流程表单-外网-招标管理 服务实现类
 * </p>
 *
 * @author Movitech Mobile
 * @since 2018-04-26
 */
@Service
public class WFlowFormExtMngServiceImpl extends ServiceImpl<WFlowFormExtMngMapper, WFlowFormExtMng> implements WFlowFormExtMngService {

    @Autowired
    private ExtWFlowFormExtMngMapper extWFlowFormExtMngMapper;
    @Override
    public Page<ExtWFlowFormExtMng>  selectPage(Page<ExtWFlowFormExtMng> page, BidManageReqVo vo) {
        LicenseUtil.INSTANCE.validate();
        Map<String,Object> param = Maps.newHashMap();
        param.put("user_id",vo.getSupplierId());
        param.put("form_title",vo.getTitle());
        page.setRecords(extWFlowFormExtMngMapper.selectExtList(page,param));
        return page;
    }

    @Override
    public void updateByFormIdAndSupplierId(WFlowFormExtMng wFlowFormExtMng) {
        LicenseUtil.INSTANCE.validate();
        EntityWrapper<WFlowFormExtMng> entityWrapper=new EntityWrapper();
        WFlowFormExtMng where = new WFlowFormExtMng();
        where.setUserId(wFlowFormExtMng.getUserId());
        where.setFlowFormId(wFlowFormExtMng.getFlowFormId());
        entityWrapper.setEntity(where);
        update(wFlowFormExtMng,entityWrapper);
    }

    @Override
    public void updateStatusByFormIdAndStatusNEqSubStatus(String changeStatus, String formId, String notEqStatus) {
        EntityWrapper<WFlowFormExtMng> entityWrapper=new EntityWrapper();
        LicenseUtil.INSTANCE.validate();
        WFlowFormExtMng where = new WFlowFormExtMng();
        where.setFlowFormId(formId);
        entityWrapper.setEntity(where);
        if(notEqStatus!=null)
             entityWrapper.ne("flow_form_sub_status",notEqStatus);
        WFlowFormExtMng wFlowFormExtMng = new WFlowFormExtMng();
        wFlowFormExtMng.setFlowFormStatus(changeStatus);
        update(wFlowFormExtMng,entityWrapper);
    }

    @Override
    public WFlowFormExtMng selectByFormIdAnSupplierId(String formId, String supllierId) {
        LicenseUtil.INSTANCE.validate();
        EntityWrapper<WFlowFormExtMng> entityWrapper=new EntityWrapper();
        WFlowFormExtMng where = new WFlowFormExtMng();
        where.setUserId(supllierId);
        where.setFlowFormId(formId);
        entityWrapper.setEntity(where);
        return selectOne(entityWrapper);
    }
}
